package com.heqiang.repository;

import com.heqiang.domain.Admin;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;


import java.io.Serializable;
import java.util.List;


/**
 * @Author zhangheqiang
 * @Date 2020/3/18
 **/
public interface AdminRepository extends JpaRepository<Admin, Long>, JpaSpecificationExecutor<Admin>, Serializable {
    /****************************************************************************************************************** SQL *********************************************************************************************/
    //查询-根据账号&phone(原生SQL)
    @Query(value = "select * from admin where account = ?1 or phone = ?2", nativeQuery = true)
    List<Admin> findAll(String account, String phone);


    /****************************************************************************************************************** JPQL *********************************************************************************************/
    //查询
    @Query("from  Admin where account like %:account%  order by id")
    List<Admin> findAdmin(@Param("account") String userName);


    //编辑
    @Query("update Admin set account =?2 where id = ?1")
    @Modifying
    void modify(Long id, String account);


    /****************************************************************************************************************** Method ********************************************************************************************/
    //查询-用户名模糊和手机号精确查询
    List<Admin> findByAccountLikeAndPhone(String account, String phone);

    //查询-用户名和手机号模糊查询
    List<Admin> findByAccountLikeAndPhoneLike(String account, String phone);

    //查询-精确查询
    List<Admin> findByAccount(String account);

    //查询-模糊查询
    List<Admin> findByAccountLike(String account);


}
